package com.ltkj.ticket.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ltkj.common.log.annotation.Log;
import com.ltkj.common.log.enums.BusinessType;
import com.ltkj.common.security.annotation.RequiresPermissions;
import com.ltkj.ticket.domain.TicType;
import com.ltkj.ticket.service.ITicTypeService;
import com.ltkj.common.core.web.controller.BaseController;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.common.core.utils.poi.ExcelUtil;
import com.ltkj.common.core.web.page.TableDataInfo;

/**
 * 票种Controller
 * 
 * @author ruoyi
 * @date 2023-08-31
 */
@Api(tags = "票种")
@RestController
@RequestMapping("/type")
public class TicTypeController extends BaseController
{
    @Autowired
    private ITicTypeService ticTypeService;

    /**
     * 查询票种列表
     */
    @ApiOperation("查询票种列表")
    @RequiresPermissions("ticket:type:list")
    @GetMapping("/list")
    public TableDataInfo list(TicType ticType)
    {
        startPage();
        List<TicType> list = ticTypeService.selectTicTypeList(ticType);
        return getDataTable(list);
    }

    /**
     * 导出票种列表
     */
    @ApiOperation("导出票种列表")
    @RequiresPermissions("ticket:type:export")
    @Log(title = "票种", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TicType ticType)
    {
        List<TicType> list = ticTypeService.selectTicTypeList(ticType);
        ExcelUtil<TicType> util = new ExcelUtil<TicType>(TicType.class);
        util.exportExcel(response, list, "票种数据");
    }

    /**
     * 获取票种详细信息
     */
    @ApiOperation("获取票种详细信息")
    @RequiresPermissions("ticket:type:query")
    @GetMapping(value = "/{ticTypeId}")
    public AjaxResult getInfo(@PathVariable("ticTypeId") Long ticTypeId)
    {
        return success(ticTypeService.selectTicTypeByTicTypeId(ticTypeId));
    }

    /**
     * 新增票种
     */
    @ApiOperation("新增票种")
    @RequiresPermissions("ticket:type:add")
    @Log(title = "票种", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TicType ticType)
    {
        return toAjax(ticTypeService.insertTicType(ticType));
    }

    /**
     * 修改票种
     */
    @ApiOperation("修改票种")
    @RequiresPermissions("ticket:type:edit")
    @Log(title = "票种", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TicType ticType)
    {
        return toAjax(ticTypeService.updateTicType(ticType));
    }

    /**
     * 删除票种
     */
    @ApiOperation("删除票种")
    @RequiresPermissions("ticket:type:remove")
    @Log(title = "票种", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ticTypeIds}")
    public AjaxResult remove(@PathVariable Long[] ticTypeIds)
    {
        return toAjax(ticTypeService.deleteTicTypeByTicTypeIds(ticTypeIds));
    }
}
